package com.hqyj.fj.javaSpringBoot.modules.test.dao;

import com.hqyj.fj.javaSpringBoot.modules.account.entity.User;
import com.hqyj.fj.javaSpringBoot.modules.test.entity.City;
import com.hqyj.fj.javaSpringBoot.modules.test.entity.Student;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRepository extends JpaRepository<User,Integer>, JpaSpecificationExecutor<User> {

    User findFirstByUserNameAndEmail(String  userName,String email);

    User findFirstByUserNameAndPassword(String userName,String password);

    @Query(nativeQuery = true,   value = "insert  into account_user (user_name,email,password)" +
            "values (:#{#user.userName},:#{#user.email},:#{#user.password})")
    @Modifying
    void insertStudent(@Param("user") User user);

    @Query(value="from User where id = :id")
    User getUserById(@Param("id") int id);

}